runOnStartup(async runtime => {
    runtime.addEventListener("tick", () => tick())
    runtime.getLayout("MainLevel").addEventListener("afterlayoutstart", () => init())
});
function tick() {
    if (runtime.layout.name != "MainLevel") return;
}
function init() {
    accLoseGameUI.whenClickRestartButton()
}
globalThis.accLoseGameUI = {
    whenClickRestartButton: function () {
        window.addEventListener("clickButton", (e) => {
            /** @type {ITextInstance} */
            let buttonInstance = e.detail[0]
            if (buttonInstance.instVars.ID == 20) {
                accLoseGameUI.reStratGame()
            }
        })
    },
    reStratGame: function () {
        LoseGameLayerEffect.rebackPosistion()
        /**@type {ILayout} */
        let Gamelayout = runtime.getLayout("MainLevel")
        /**@type {ILayer} */
        let loseLayer = Gamelayout.getLayer("loseHUD")
        /**@type {ISpriteInstance} */
        let player = runtime.objects.PlayerCollision.getFirstInstance()
        /**@type {I8DirectionBehaviorInstance} */
        let behaviors = player.behaviors['8Direction']
        /**@type {ISpriteInstance} */
        let PlayerAnimations = runtime.objects.PlayerAnimations.getFirstInstance()
        let PlayerBillboard = runtime.objects.PlayerBillboard.getFirstInstance()
        loseLayer.isVisible = false
        behaviors.isEnabled = true
        PlayerBillboard.zElevation = 0
        playerSelfdata.playerHeart = playerSelfdata.initHeart
        for (let allDuck of runtime.objects.DuckObject.instances()) {
            /**@type {ISpriteInstance} */
            let all_duck = allDuck
            all_duck.destroy()
        }
        /**
         * 重置分数
         */
        game_recordtimescore.record()
        uiPlayerHeart_Spwn.spwn()
        playerSelfdata.Score = 0
        playerSelfdata.LiveTime = 0 //s 

    },
}
export default accLoseGameUI;